<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">











<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Maven2 Java Formatter Plugin - Plugin Usage</title>
    <style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
    </style>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
          <meta name="author" content="Matt Blanchette" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                    <span id="bannerLeft">
    
            Maven2 Java Formatter Plugin
    
            </span>
                    <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
  
  
    
            <div class="xleft">
        Last Published: 2011-03-04
                      </div>
            <div class="xright">      
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
  
  
    
                   <h5>Overview</h5>
            <ul>
              
    <li class="none">
                    <a href="http://code.google.com/p/maven-java-formatter-plugin/" class="externalLink">Project Home</a>
          </li>
              
    <li class="none">
                    <a href="index.html">Introduction</a>
          </li>
              
    <li class="none">
                    <a href="plugin-info.html">Goals</a>
          </li>
              
    <li class="none">
              <strong>Usage</strong>
        </li>
          </ul>
              <h5>Examples</h5>
            <ul>
              
    <li class="none">
                    <a href="examples.html#Setting_Source_Files">Source Files</a>
          </li>
              
    <li class="none">
                    <a href="examples.html#Setting_Compiler_Version">Compiler Version</a>
          </li>
              
    <li class="none">
                    <a href="examples.html#System_Independent_Line_Endings">Line Endings</a>
          </li>
              
    <li class="none">
                    <a href="examples.html#Source File Encoding">File Encoding</a>
          </li>
              
    <li class="none">
                    <a href="examples.html#Custom_Configuration_File">Custom Formatting</a>
          </li>
              
    <li class="none">
                    <a href="examples.html#Multimodule_Configuration">Multimodule</a>
          </li>
          </ul>
              <h5>Project Documentation</h5>
            <ul>
              
                
              
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
            
      
              
        <li class="collapsed">
                    <a href="project-info.html">Project Information</a>
                </li>
              
                
              
      
              
        <li class="collapsed">
                    <a href="project-reports.html">Project Reports</a>
                </li>
          </ul>
                                           <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
  
  
    
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section"><h2>Plugin Usage</h2>
<p>The following instructions describe how to use the plugin in its simplest configuration. The following pom section will be able to get you started using the plugin. </p>
<div class="source"><pre>&lt;project ...&gt;
    ...
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;com.googlecode.maven-java-formatter-plugin&lt;/groupId&gt;
        &lt;artifactId&gt;maven-java-formatter-plugin&lt;/artifactId&gt;
        &lt;version&gt;0.3.1&lt;/version&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
    ...
&lt;/project&gt;</pre>
</div>
<p>With this configuration, java source files in <tt>src/main/java</tt> and <tt>src/test/java</tt> of the project will be formatted using the default compiler version (1.5) and line ending of the current system.</p>
<p>Run the plugin with the <tt>format</tt> goal.</p>
<div class="source"><pre>mvn java-formatter:format</pre>
</div>
<p>In order to format the source files during the build, include the <tt>format</tt> goal in the plugin executions.</p>
<div class="source"><pre>&lt;project ...&gt;
    ...
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;com.googlecode.maven-java-formatter-plugin&lt;/groupId&gt;
        &lt;artifactId&gt;maven-java-formatter-plugin&lt;/artifactId&gt;
        &lt;version&gt;0.3.1&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;format&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
    ...
&lt;/project&gt;</pre>
</div>
<p>The source files will be formatted prior to compilation in the build lifecycle.</p>
<p>Run the plugin during the build with the <tt>compile</tt> goal.</p>
<div class="source"><pre>mvn compile</pre>
</div>
<p>If you want to override the default plugin behavior, check out <a href="examples.html">custom configurations</a> and <a href="plugin-info.html">how to configure</a> it.</p>
</div>

      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">&#169;  
          2011
    
          
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>
